const express = require("express");
const database = require("./database");
const app = express();

/**
 * 用户服务端
 * 1. 实现登录生成token返回客户端
 * 2. token过期，refresh_token刷新token
 */

app.get("/", (req, res) => {
  res.send("hello world");
});

app.get("/login", (req, res) => {
  const { query } = req;
  const { userName, password } = query;
  const { token, time } = database.createNewToken(userName);
  res.send({ token, time });
});

app.get("/getNewToken", (req, res) => {
  const { query } = req;
  const { token, time } = database.replaceToken(query.token)
  res.send({ token, time });
})

app.listen("1313", () => {
  console.log("Server has Open Port 1313");
});
